var String = require("../generic_class/String.js");
var MyFs = require("../generic_class/MyFs.js");

var getRoot = function(){
    var path = new String(__dirname);
    var pathNodes = path.split(new String("\\"));

    for(var i=0; i<pathNodes.length; i++){
        var needPath = "";

        for(var j=0; j<(pathNodes.length-i); j++){
            needPath = needPath + "/" + pathNodes[j].value;
        }

        needPath = needPath.substring(1, needPath.length);
        if(MyFs.isHaveFileInCurrentDir(needPath, "package.json")){
            return needPath;
        }
    }
}

var imports = function(packageName){
    var packagePath = new String(packageName);
    packagePath.replaceAll(new String("root"), new String(""));

    var root = getRoot();
    packagePath = (new String(root)).concat(packagePath);
    packagePath.replaceAll(new String("."), new String("/"));

    return packagePath.value;
}

module.exports = imports;


